import axios from 'axios'
import { ElMessage } from 'element-plus'
import { router } from './router'
const instance = axios.create({
    baseURL: '/api/'
})
instance.interceptors.response.use(
    res => {
        if (res.status === 200) {
            return Promise.resolve(res)
        } else {
            return Promise.reject(res)
        }
    },
    err => {
        if (err.response.status == 403) {
            router.push('/login')
        } else {
            ElMessage({
                type: 'error',
                message: '请求失败, 请检查网络设置'
            })
        }
        return Promise.reject(err.response)
    }
)
export default instance